<template>
  <div class="Personal_information">
    <public-com></public-com>
    <el-button type="primary" @click="chaxui()">查看个人信息</el-button>
    <el-button type="primary" @click="dialogFormVisible = true">修改个人信息</el-button>
    <el-dialog title="收货地址" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="姓名" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="身份证号" :label-width="formLabelWidth">
          <el-input v-model="form.userid" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="性别" :label-width="formLabelWidth">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option label="女" value="女"></el-option>
            <el-option label="男" value="男"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="xuigai(),dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>
    
    <div class="flexd box">
      <p>用户账号：{{ phone }}</p>
      <p>姓名：{{ name }}</p>
      <p>身份号：{{ userid }}</p>
      <p>性别：{{ sex }}</p>
    </div>

    <footer-com></footer-com>
  </div>
</template>
<script>
import axios from "axios";
import qs from "qs";
import PublicCom from "@/components/PublicCom.vue";
import FooterCom from "@/components/FooterCom.vue";
export default {
  name: "Personal_information",
  components: {
    PublicCom,
    FooterCom,
  },
  data() {
    return {
      dialogFormVisible: false,
      formLabelWidth: "120px",
      form: {
        name: null,
        userid:null,
        sex: null,
        delivery: false,
      },
      phone: null,
      name: null,
      userid: null,
      sex: null,
    };
  },
  methods: {
    chaxui() {
      this.phone = sessionStorage.getItem("user");
      axios
        .get("api/UserInfo/getInfo.do", {
          params: {
            user_phone: this.phone,
          },
        })
        .then((res) => {
          if (res != null) {
            console.log(res.data);
            (this.phone = res.data.user_phone),
              (this.name = res.data.user_name),
              (this.userid = res.data.user_idcard),
              (this.sex = res.data.user_sex);
          }
        });
    },
    xuigai() {
      this.phone = sessionStorage.getItem("user");
      // let data = qs.stringify();
      // console.log(this.form.name);
      // console.log(data)
      axios.get("api/UserInfo/updateInfo.do", {params:{
        user_phone: this.phone,
        user_name: this.form.name,
        user_idcard: this.form.userid,
        user_sex: this.form.sex,
      }}).then((res) => {
        if (res != 0) {
          alert("修改成功！")
        } else {
          alert("修改失败！")
        }
      });
    },
  },
};
</script>
<style scoped>
.Personal_information {
  width: 100vw;
  height: 100vh;
  background-image: url("../assets/png80.png");
}
.box {
  width: 40%;
  height: 40%;
  background-color: rgb(233, 227, 227);
  margin: 0 auto;
  margin-top: 50px;
  padding: 20px;
  border-radius: 20px;
}
.box > p {
  padding: 10px;
}
.el-button--primary {
  color: #fff;
  background-color: #e30001;
  border-color: #e30001;
  border-radius: 10px;
}
</style>